package org.karelun.gef.actions;

import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionFactory;
import org.karelun.gef.commands.CutNodeCommand;
import org.karelun.gef.editors.ClassDiagramEditor;
import org.karelun.gef.parts.NodePart;

public class CutAction extends SelectionAction {

	public CutAction(IWorkbenchPart part) {
		super(part);
	}

	protected void init() {
		setId(ActionFactory.CUT.getId());
		setEnabled(false);
	}

	public void run() {
		CutNodeCommand command = new CutNodeCommand(getSelection());
		// command.execute();

		IWorkbenchPart part = getWorkbenchPart();
		if (part instanceof ClassDiagramEditor) {
			getCommandStack().execute(command);
		}
	}

	protected boolean calculateEnabled() {
		IStructuredSelection s = (IStructuredSelection) this.getSelection();
		if (s == null) {
			return false;
		}
		Object obj = s.getFirstElement();
		if (obj instanceof NodePart) {
			return true;
		}
		return false;
	}

}
